<template>
	<Table ref="tableRef" :url="URL_LAILURELIST" :columns="data.columns" :handles="data.handles"
		:query="data.query" :toolbar="data.toolbar"></Table>
</template>

<script lang="ts" setup name="alarmSettingList">
	import Table from '@/components/table/index.vue';
	import {
		URL_LAILURELIST,
		deleteFailureInfo
	} from '@/service/apis/alarm';
	import moment from 'moment';

	const router = useRouter();

	const tableRef = ref();

	const emit = defineEmits(['get-update']);
	onActivated(() => {
		emit('get-update', (flag : boolean) => {
			if (flag) {
				tableRef.value?.getData();
			}
		});
	});

	const data = reactive({
		pickDate: null as any,
		columns: [
			{
				prop: 'failureReason',
				label: '故障原因',
			},
			{
				prop: 'failureBit',
				label: '故障码',
			},
			{
				prop: 'failureLevel',
				label: '故障等级',
			},
			{
				prop: 'failureMsg',
				label: '故障描述',
				width: 560,
			}
		],
		toolbar: [
			{
				label: '新增',
				permission: 'failureList.add',
				icon: 'icon-add',
				type: 'primary',
				handle: (row : any) => {
					router.push({
						name: 'failureAdd',
					});
				},
			}
		],
		query: [
			{
				label: '故障码',
				prop: 'failureBit',
				comName: 'input',
				props: {
					placeholder: '请输入故障码',
				},
			},
			{
				label: '故障原因',
				prop: 'failureReason',
				comName: 'input',
				props: {
					placeholder: '请输入故障原因',
				},

			},
			{
				label: '故障等级',
				prop: 'failureLevel',
				comName: 'input',
				props: {
					placeholder: '请输入故障等级',
				},

			},
		],
		handles: [
			{
				label: '修改',
				permission: 'failureList.edit',
				handle: (row : any) => {
					router.push({
						name: 'failureEdit',
						query: { id: row.id },
					});
				},
			},
			{
				label: '删除',
				color: '#FA3939',
				permission: 'failureList.delete',
				handle: (row : any) => {
					ElMessageBox.confirm('此操作将永久删除该数据，是否继续？', '提示', {
						confirmButtonText: '确认',
						cancelButtonText: '取消',
						type: 'warning',
					}).then(() => {
						deleteFailureInfo({
							id: row.id,
						}).then((res : any) => {
							tableRef.value.getData();
						});
					});
				},
			},
		],
	});
	
</script>